#!/usr/bin/env python

# -------
# Imports:
# -------
import os, re
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template
from settings import *
from core.models import Image

# -----------------------------------
class Pipeline(webapp.RequestHandler):
# -----------------------------------
    # -----------
    def get(self):
    # -----------
        # Parse out the ID of the image
        urlIdM = re.search(r'/(?P<id>\w+)', self.request.path)
        urlId = int(urlIdM.group('id'))
        sourceImgUrl = '/image/source/%i' % urlId

        # Make sure the image exists
        image = Image.get_by_id(urlId)
        if image is not None:
            path = os.path.join(TEMPLATE_DIR, 'pipeline.html')
            self.response.out.write(template.render(path, {'current': 'threshold', 'sourceImgUrl': sourceImgUrl, 'imgId': urlId}))
        else:
            path = os.path.join(TEMPLATE_DIR, 'image_not_found.html')
            self.response.out.write(template.render(path, {'current': 'threshold'}))
